<?php

function send_load_list_students()
{
   if(isset($_SESSION['logged_in']) && $_SESSION['permissions'] == 'Faculty')
      return true;
}

function send_menu_list_students()
{
   $content = "<br><a href=?q=list_students>List Students</a><br>";
   $content .= "<a href=?q=list_students_search>Search Students</a><br>";
   return $content;
}

function send_content_list_students()
{
   if(isset($_GET['q']) && $_GET['q'] == "list_students")
   {
      $query = "select uid,f_name from students where faculty = '$_SESSION[user_name]'";
      $result = mysql_query($query);
      $num = mysql_num_rows($result);
      if($num == 0)
         return "Sorry, No student registered under you";

      $content = "";
      $count = 1;
      while($row = mysql_fetch_array($result))
      {
         $content .= "$count. $row[0], $row[1]<br>";
         $count++;
      }

      return $content;
   }
   else if(isset($_GET['q']) && $_GET['q'] == "list_students_search")
   {
      $content = '<form name="list_students_search" action="?q=list_students_search_action" method="post">
                  <table>
                  <tr><td>Keyword:</td><td><input name="keyword" type="text" /></td></tr>
                  <tr><td>Submit:</td><td><input name="submit" type="submit"></td></tr>
                  </table>
                  </form>
                 ';
      return $content;
   }
   else if(isset($_GET['q']) && $_GET['q'] == "list_students_search_action")
   {
      $query = "select uid,f_name from students where faculty = '$_SESSION[user_name]'";
      $result = mysql_query($query);
      $num = mysql_num_rows($result);
      if($num == 0)
         return "Sorry, No student registered under you";

      if(!isset($_POST['keyword']) || $_POST['keyword'] == "")
         return "Keyword required";
      $keyword = $_POST['keyword'];
      
      $query = "select uid,f_name from students where faculty = '$_SESSION[user_name]' && (f_name like '%$keyword%' or uid like '%$keyword%' or department like '%$keyword%' or project_title like '%$keyword%')";
      $result = mysql_query($query);

      $num = mysql_num_rows($result);
      if($num == 0)
         return "Sorry, no match found";
      
      $content = "";
      $count = 1;
      while($row = mysql_fetch_array($result))
      {
         $content .= "$count. $row[0], $row[1]<br>";
         $count++;
      }
   
      return $content;
   }
}

function send_content_other_list_students()
{

}

?>
